<?php
/**
 * Base ADMIN controller
 *
 * @author Dima
 *
 */

class modules_admin_controllers_ControllerBase extends Zend_Controller_Action
{
	/**
	 * Shows if only logged user can access to this controller
	 * @var bool
	 */
	
	protected $_bForLoggedUsersOnly = true;
	protected $_role = '';

	public function init()
	{
		$Path      = 'includes/';
		$Extension = '.phtml';
		
		$this->view->layout()->setLayoutPath(APPLICATION_PATH . '/modules/admin/layouts/');
		
		$MenuTemplate 	       = $Path . 'menu'	           . $Extension;
		$UserMenuTemplate      = $Path . 'usermenu_logged' . $Extension;
		$TopMenuTemplate       = $Path . 'topmenu'         . $Extension;

		if (! Lemar_User::isLogged() && $this->_bForLoggedUsersOnly)
		{
			/** If user is not logged in and controller is for logged users only - redirect to start page */

			$oRequest = $this->getRequest();
			$category = $oRequest->getParam('category');
			$oZendSession = Zend_Registry::getInstance()->get('Zend_Session_Namespace');
			$oZendSession->category = $category;

			$this->_redirect('/login/');
		}

		$oZendSession = Zend_Registry::getInstance()->get('Zend_Session_Namespace');
		$errorMessage = $oZendSession->errorMessage;
		$this->view->errorMessage = $errorMessage;

		$this->view->MenuTemplate 			= $MenuTemplate;
		$this->view->TopMenuTemplate        = $TopMenuTemplate;
		$this->view->UserMenuTemplate       = $UserMenuTemplate;

		$this->view->headLink()->appendStylesheet('/css/reset.css');
		$this->view->headLink()->appendStylesheet('/css/960.css');
        $this->view->headLink()->appendStylesheet('/css/admin/main.css');
		$this->view->headLink()->appendStylesheet('/css/jquery.alerts.css');
		$this->view->headLink()->appendStylesheet('/css/sexybuttons.css');
		
		$this->view->headLink()->appendStylesheet('/css/admin/style.css');

		$this->view->headScript()->appendFile('/js/lib/jquery.js');
		$this->view->headScript()->appendFile('/js/lib/jquery.alerts.js');

		$oUser = Lemar_User::getLoggedUser();
		if (isset($oUser->role))
			$this->_role = $oUser->role;
		$this->view->role = $this->_role;

	}
}